package com.jade.bss.customer.principal;

import java.security.Principal;
import javax.inject.Named;

/**
 * 简单的PrincipalFactory实现，考虑principal为SimplePrincipal的情况。
 *
 * @author sky
 * @version 1.0 13-4-18 上午10:08
 */
@Named ("bss_principalFactory")
public class SimplePrincipalFactory implements PrincipalFactory
{
    public Principal createPrincipal(String type, String name)
    {
        SimplePrincipal principal = new SimplePrincipal();
        principal.setType(type);
        principal.setName(name);
        return principal;
    }

    public String getPrincipalType(Principal principal)
    {
        if (principal instanceof SimplePrincipal) {
            return ((SimplePrincipal)principal).getType();
        }
        else {
            return SimplePrincipal.TYPE_ADMIN;
        }
    }
}
